package com.hjb.service.controller.withdraw;

import com.hjb.service.domain.product.SiteUserBuy;
import com.hjb.service.domain.withdraw.PayCashWithdraw;
import com.hjb.service.gateway.baofoo.domain.request.TransReqBF0040002;
import com.hjb.service.recharge.RechargeService;
import com.hjb.service.withdraw.WithDrawService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by gy on 2017/7/28.
 * 提现
 */
@RestController
@RequestMapping("/withdraw")
public class WithDrawController {
	private Logger log = LoggerFactory.getLogger(getClass());

	@Autowired
	private WithDrawService withDrawService;

	/**
	 * 用户提现
	 * @param amount
	 * @param userId
	 * @param orderId
	 * @return
	 */
	@RequestMapping(value = "/withdraw", method = {RequestMethod.GET, RequestMethod.POST})
	@ResponseBody
	public Map<String, Object> withdraw(String amount, String userId, String orderId) {
		Map<String, Object> resMap = new HashMap<String, Object>();
		try {
			PayCashWithdraw payCashWithdraw = new PayCashWithdraw();
			payCashWithdraw.setUserId(2001);
			payCashWithdraw.setAmount(new BigDecimal("10"));
			payCashWithdraw.setOrderId(String.valueOf(System.currentTimeMillis()+payCashWithdraw.getUserId()));
			resMap = withDrawService.withdraw(payCashWithdraw);
		}catch (Exception e){
			log.info("用户提现请求失败"+e);
		}
		return resMap;
	}

	/**
	 * 提现查询
	 * @param request
	 * @return
	 */
//	@RequestMapping("/withdrawQuery")
//	@ResponseBody
//	public Map<String, Object> withdrawQuery(HttpServletRequest request) {
//		Map<String, Object> resMap = new HashMap<String, Object>();
//		try {
//			TransReqBF0040002 transReqData = new TransReqBF0040002();
//			transReqData.setTrans_batchid("20794222");
//			transReqData.setTrans_no("1501321473365");
//			withDrawService.withdrawQuery(transReqData);
//		}catch (Exception e){
//			log.info("提现失败");
//		}
//		return resMap;
//	}

	/**
	 * 提现通知
	 * @param req
	 * @param resp
	 * @return
	 */
//	@RequestMapping("/withdrawNotify")
//	@ResponseBody
//	public void withdrawNotify(HttpServletRequest req, HttpServletResponse resp) {
//		Map<String, Object> resMap = new HashMap<String, Object>();
//		try {
//			String member_id=req.getParameter("member_id");
//			String terminal_id=req.getParameter("terminal_id");
//			String data_type=req.getParameter("data_type");
//			String data_content=req.getParameter("data_content");
//			resp.setContentType("text/html;charset=UTF-8");
//			PrintWriter out = resp.getWriter();
//			if (data_content == null ||"".equals(data_content)) {
//				log.info("接受数据不能为空！");
//				throw new RuntimeException("接受数据不能为空！");
//			}
//			log.info("接收的返回数据：member_id" + member_id+",terminal_id:"+terminal_id+",data_content:"+data_content);
//			String result = withDrawService.withdrawNotify(data_content);
//			// 业务逻辑判断
//			if ("OK".equals(result)){
//				out.write("OK");
//			}
//		}catch (Exception e){
//			log.info("通知处理失败");
//		}
//	}
}
